<?php

class ProjectComments extends Model {

	function ProjectComments() {
		parent::Model();
	}

	function create( $project_id, $text, $add_date = null ) {
		if( $add_date != null ) {
			$sql = 'insert into `project_comments`'
				.'(`project_id`, `text`, `add_date`)'
				.'values( ?, ?, ?)';
			$this->db->query($sql, array($project_id, $text, $add_date));
		} else {
			$sql = 'insert into `project_comments`'
				.'(`project_id`, `text`, `add_date`)'
				.'values( ?, ?, now())';
			$this->db->query($sql, array($project_id, $text));
		}
	}

	function fetch( $comment_id ) {
		$sql = 'select * from `project_comments` where `comment_id`=?';
		$r = $this->db->query($sql, array($comment_id));
		return $r->row();
	}

	function fetch_by_project( $project_id ) {
		$sql = 'select * from `project_comments` '
			.'where `project_id`=? '
			.'order by `add_date` asc';
		$r = $this->db->query( $sql, array($project_id) );
		return $r->result();
	}

	function remove( $comment_id ) {
		$sql = 'delete from `project_comments` where `comment_id`=?';
		$this->db->query($sql, array($comment_id));
	}

}

?>
